package com.analysis.server.model;

import java.time.LocalDateTime;

/**
 * 慢SQL分析结果实体类
 */
public class SlowSqlResult {
    
    private String sql;                    // SQL语句
    private LocalDateTime startTime;       // 开始时间
    private LocalDateTime endTime;         // 结束时间
    private long durationMillis;           // 执行时长（毫秒）
    private String mapperName;             // Mapper名称
    private String parameters;             // SQL参数
    private int lineNumber;                // 日志行号
    private String logLine;                // 原始日志行
    
    public SlowSqlResult() {}
    
    public SlowSqlResult(String sql, LocalDateTime startTime, LocalDateTime endTime, 
                        String mapperName, String parameters, int lineNumber, String logLine) {
        this.sql = sql;
        this.startTime = startTime;
        this.endTime = endTime;
        this.durationMillis = java.time.Duration.between(startTime, endTime).toMillis();
        this.mapperName = mapperName;
        this.parameters = parameters;
        this.lineNumber = lineNumber;
        this.logLine = logLine;
    }
    
    // Getters and Setters
    public String getSql() {
        return sql;
    }
    
    public void setSql(String sql) {
        this.sql = sql;
    }
    
    public LocalDateTime getStartTime() {
        return startTime;
    }
    
    public void setStartTime(LocalDateTime startTime) {
        this.startTime = startTime;
    }
    
    public LocalDateTime getEndTime() {
        return endTime;
    }
    
    public void setEndTime(LocalDateTime endTime) {
        this.endTime = endTime;
    }
    
    public long getDurationMillis() {
        return durationMillis;
    }
    
    public void setDurationMillis(long durationMillis) {
        this.durationMillis = durationMillis;
    }
    
    public String getMapperName() {
        return mapperName;
    }
    
    public void setMapperName(String mapperName) {
        this.mapperName = mapperName;
    }
    
    public String getParameters() {
        return parameters;
    }
    
    public void setParameters(String parameters) {
        this.parameters = parameters;
    }
    
    public int getLineNumber() {
        return lineNumber;
    }
    
    public void setLineNumber(int lineNumber) {
        this.lineNumber = lineNumber;
    }
    
    public String getLogLine() {
        return logLine;
    }
    
    public void setLogLine(String logLine) {
        this.logLine = logLine;
    }
    
    public String getDurationFormatted() {
        if (durationMillis >= 60000) {
            return String.format("%.2f分钟", durationMillis / 60000.0);
        } else {
            return String.format("%.2f秒", durationMillis / 1000.0);
        }
    }
}
